from django.shortcuts import render
import json
from .ana import do_obj
REMOTE_HOST = "https://pyecharts.github.io/assets/js"
# Create your views here.
def index(request):
    context={
        'userlike':do_obj.get_like_most_user(),
        'darkman': do_obj.get_dark_man().decode()
    }
    return render(request,'douabn/hao.html',context)
def get__everv_movie_user_comment_num(request):

    bar=do_obj.make_everv_movie_user_comment_num()
    context = dict(

        myechart=bar.render_embed(),

        host=REMOTE_HOST,

        script_list=bar.get_js_dependencies()
    )
    return render(request,'douabn/index.html',context)
def every_movie_like_num(request):

    bar=do_obj.make_every_movie_like_num()
    context = dict(

        myechart=bar.render_embed(),

        host=REMOTE_HOST,

        script_list=bar.get_js_dependencies()
    )
    return render(request, 'douabn/index.html', context)
def make_every_movie_star_bar(request):

    bar=do_obj.make_every_movie_star_bar()
    context = dict(

        myechart=bar.render_embed(),

        host=REMOTE_HOST,

        script_list=bar.get_js_dependencies()
    )
    return render(request, 'douabn/index.html', context)
def make_real_every_movie_star_bar(request):

    bar=do_obj.make_real_every_movie_star_bar()
    context = dict(

        myechart=bar.render_embed(),

        host=REMOTE_HOST,

        script_list=bar.get_js_dependencies()
    )
    return render(request, 'douabn/index.html', context)
def fuchou_every_day_comment_num(request):
    bar=do_obj.make_line_fuchou_every_day_comment_num()
    context = dict(

            myechart=bar.render_embed(),

            host=REMOTE_HOST,

            script_list=bar.get_js_dependencies()
        )
    return render(request, 'douabn/index.html', context)
def make_most_20_user_comment_bar(request):
    bar=do_obj.make_most_20_user_comment_bar()
    context = dict(

            myechart=bar.render_embed(),

            host=REMOTE_HOST,

            script_list=bar.get_js_dependencies()
        )
    return render(request, 'douabn/index.html', context)
def make_table_less_2_but_like_most3(request):
    b={}
    li=[]
    info=do_obj.get_every_star_lower_2_and_like_3()
    for i, k in info.items():
        key = i.decode()
        vv = str(json.loads(k)).replace('{', '').replace('}', '')
        vvv = [key] + vv.split(',')
        li.append(vvv)
        print(type(vv))
        b[key] = vvv
    print(li)
    b = {
        'movie':li,
        'type':'评论低于2分，点赞前3个评论'
    }
    print(b)
    return render(request,'douabn/comment.html',b)
def make_table_comment_like_most_5(request):
    b = {}
    li = []
    info = do_obj.get_every_movie_comment_like_5()
    for i, k in info.items():
        key = i.decode()
        vv = str(json.loads(k)).replace('{', '').replace('}', '')
        vvv = [key] + vv.split(',')
        li.append(vvv)
        print(type(vv))
        b[key] = vvv
    print(li)
    b = {
        'movie': li,
        'type':'每部电影评论点赞前五名的评论',
    }
    print(b)
    return render(request, 'douabn/comment.html', b)